package New;
import java.util.ArrayList;
/**
 * 使用最少的循环在集合中查找出最长的字符串
 */
public class StringLongest {
    public static void main(String[] args) {
     ArrayList<String> l = forLongest(new String[]{"one", "two", "three", "four", "five", "six","seven"});
        System.out.println(l);
    }
    private static ArrayList<String> forLongest(String[] s) {
        ArrayList list = new ArrayList();
        int target = 0;
        for (int i = 1; i <s.length; i++) {
           if(s[target].length()<s[i].length()){
                target =i;
            }
        }
        for (int i = 0; i <s.length; i++) {
            if (s[i].length()==s[target].length()){
                list.add(s[i]);
            }
        }
        return list;
//        list.sort();
    }

}
